package net.itbrother.controller.user;


import java.util.List;

import net.itbrother.model.User;
import net.itbrother.service.user.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
 
@Controller
@RequestMapping("/")
public class UserController {
 
	@Autowired
	UserService userService;
	
	/**
	 * 登录
	 * @return
	 */
	@RequestMapping("/login")
	public String login(){
	    List<User> userList = userService.queryAllUser();
	    System.out.println(userList.size());
	    return "login";
	}
	
	
	/**
	 * 校验登录信息
	 * @param userCode
	 * @param userPwd
	 * @param ckcode
	 * @return
	 */
	@RequestMapping("/validLogin")
	@ResponseBody
	public String validLogin(String userCode,String userPwd,String ckcode){
		List<User> userList = userService.queryUserByUserCode(userCode);
		int flag =0;
		if(userList == null || userList.size() < 1){
			flag =1; //无用户
		}else{
			User user  = userList.get(0);
			if(!user.getUserPwd().equals(userPwd)){
				flag =2; //密码不正确
			}
			
		}
		JSONObject jo = new JSONObject();
		jo.put("flag", flag);
		return jo.toJSONString();
	}
	
	
    @RequestMapping("/index")
    public String index(){
    	List<User> userList = userService.queryAllUser();
    	System.out.println(userList.size()+"ssssssssssssssssss");
        return "index";  
    }
     
}